function LabelsUI(gtdinboxPage){
	this._gtdinboxPage = gtdinboxPage;
	this._doc = gtdinboxPage.doc;
	this._eventObservers = new EventObservers(this);	
	this._labels = gtdinboxPage._labels;
	this._sp = gtdinboxPage.sp;
	this._multiToOne = new MultiToOne(this._gtdinboxPage);
	
	this.elAlertBox = this._gtdinboxPage.gmailDOM.element("alert-box");
	this._eventObservers.observe( this.elAlertBox, "DOMNodeInserted", this.alertBoxChange, false );
	
};


LabelsUI.prototype.alertBoxChange = function(event){
	this._multiToOne.process("alert-box-change", GIPROTOTYPE.bind(this, this._alertBoxChange));
};
LabelsUI.prototype._alertBoxChange = function(event){
try{
	if( this._gtdinboxPage.view()=="s" ){
		this.viewChange();
	}
}catch(e){
	if( GTDDEBUGMODE ) alert("LabelsUI alertBoxChange\n" + e.toString());
}
};

LabelsUI.prototype.viewChange = function(){
	var doc = this._gtdinboxPage.gmailDOM.element("document");
	if( !this.elPrefix || !doc.getElementById("gtdinbox.labels-prefix") ){
		this.elPrefix = this._doc.createElement("SELECT");
			this.elPrefix.id = "gtdinbox.labels-prefix";
			this.elPrefix.className = "labels-prefix";
		
		var elOption = this._doc.createElement("OPTION");
			elOption.innerHTML = "";
		this.elPrefix.appendChild( elOption );
		
		var types = this._gtdinboxPage.settings.labels.types;
		for( t in types ){
			if( types[t].prefix!="" ){
				var elOption = this._doc.createElement("OPTION");
				elOption.innerHTML = types[t].prefix;
				elOption.value = types[t].prefix;
				this.elPrefix.appendChild( elOption );
			}
		}
		
		this.elInput = this._gtdinboxPage.gmailDOM.element("labels-create-box");
		this.elInput.parentNode.insertBefore(this.elPrefix, this.elInput);
		
		var elCreate = this.elInput.parentNode.getElementsByTagName("BUTTON")[0];
		this._eventObservers.observe( elCreate, "mousedown", this._clickCreate, true);
	}	

	if( !this.elHelp || !doc.getElementById("gtdinbox.labels-help") ){
		this.elHelp = this._doc.createElement("DIV");
			this.elHelp.id = "gtdinbox.labels-help";
			this.elHelp.className = "labels-help";
		
		this._gtdinboxPage.gmailDOM.element("labels-last-row").appendChild( this.elHelp );

		var el = this._doc.createElement("DIV");
			var msg = GTDFileIO.readFromUrl( this._gtdinboxPage.gtdinboxBrowser.getLocalHtmFile("labels") );
			var match = msg.match(/<body[^>]*>((.|\r|\n|\t|\e|\f|\a|\v)+)<\/body>/i);
			el.innerHTML = match[1];
		this.elHelp.appendChild( el );	
	}
};

LabelsUI.prototype._clickCreate = function(event){
	this.elInput.value = this.elPrefix.value + this.elInput.value;
};

LabelsUI.prototype.destroy = function(){
	this._eventObservers.destroy();
	this._multiToOne.destroy();

	this._gtdinboxPage = null;
	this._doc = null;
};